import time

from common import settings
# import requests
import httpx

client = httpx.Client(http2=True)


def fetch(page: int):
    cookies = {
        'sessionid': '0yprlq4t8ebsn0wer7bawyxw5u733fjv',
    }

    headers = {
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Cache-Control": "no-cache",
        "Cookie": "Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1714464818,1714638753,1714964192,1715582233; qpfccr=true; no-alert3=true; tk=-5773843510816912871; sessionid=0yprlq4t8ebsn0wer7bawyxw5u733fjv; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1715582249",
        "Pragma": "no-cache",
        "Priority": "u=0, i",
        "Referer": "https://match.yuanrenxue.cn/match/17",
        "Sec-Ch-Ua": "\"Chromium\";v=\"124\", \"Google Chrome\";v=\"124\", \"Not-A.Brand\";v=\"99\"",
        "Sec-Ch-Ua-Mobile": "?0",
        "Sec-Ch-Ua-Platform": "\"Windows\"",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
        "X-Requested-With": "XMLHttpRequest"
    }

    params = {
        'page': page,
    }

    response = client.get('https://match.yuanrenxue.cn/api/match/17', params=params
                          , cookies=cookies, headers=headers
                          )
    print(response.text)
    if response.status_code != 200:
        exit(500)
    return [x['value'] for x in response.json()['data']]


if __name__ == '__main__':
    values = []

    for page in range(1, 6):
        time.sleep(0.1)
        values.extend(fetch(page))
    print(sum(values))
